import query from '@dfeidao/atom-nodejs/db/query';
// import { IBaseTable } from '@dfeidao/atom-nodejs/db/interfaces';
interface Message {
	productid: string;
	role_allot_id: string;
}
interface Data {
	group: string;
	priority: string;
}
export default async function atom(msg: Message, action_id: string, session_id: string, spaceid: string) {
	const systemid = '12';
	const { exec, prepare } = query(action_id, session_id, systemid);
	const productid = msg.productid;
	const role_allot_id = msg.role_allot_id;

	prepare('allot_conditions_group', ['connector', 'group_id', 'role_allot_id', 'role_no', 'parent_group_id', 'priority'], { productid, role_allot_id }, 200, 1, ['priority'], []);

	// const [data] = await exec();
	// const dataArray = data.map((v) => {
	// 	v['group'] = 'group_' + v['priority'];
	// 	return v;
	// });
	//  version 1.2
	const [data] = await exec<Data>();
	const dataArray = data.map((v) => {
		v.group = 'group_' + v.priority;
		return v;
	});
	return dataArray;
}
